Version 3.0 User's Guide |
|
Commands: Random |
Previous |
Next Contents |
INSERT_RANDOM allows you to display a random number in your document. By default (without "range" specified), the value will be between 1 and 100. Here are a few examples:
Random #(1-100): <INSERT_RANDOM> Random #(1-5): <INSERT_RANDOM 5> Random #(1-500): <INSERT_RANDOM 500>
These commands hide or show the HTML text to users based on a random number. If the random number generated by the command is less than the "threshold" specified, the HTML text which follows the command will be hidden or shown.
If no "range" is specified, SHOW_RANDOM will use a range of 100, and the threshold is equivalent to a percentage from 1 to 100. For example, to display a line randomly:
<HIDE><SHOW_RANDOM 30> This line seen 30% of the time.
Remember that each random line is independent of the others. If you place several SHOW_RANDOM commands in sequence, more than one of these lines may be shown, and it is also possible that none will be shown. In order to ensure that one and only one line in the group is shown on a page, use the SAMERAND commands explained below.
The optional parameter "range" allows you to adjust the range of possible random values. This will show the text following the command in a fraction of the times the page is loaded, equal to the threshold divided by the range. For example:
<SHOW_RANDOM 1 3>
This would show the text following it in 33% (1/3) of the times the page is served.
Specifying a range greater than the default of 100 allows for a finer level of control over the command than a single percentage, and in many cases simplifies the logic of your HIDE and SHOW commands. It also makes it possible to select from more than 100 possible options. The range for randomly generated values is 1 to 10,000.
This command inserts the most recently generated random number into the page without generating a new random number.
These commands hide or show the HTML text to users based on the random value generated in a preceeding HIDE, SHOW or INSERT_RANDOM command. When the preceding RANDOM command has no range specified, the "threshold" is a percentage from 1 to 100.
SHOW_SAMERAND may only be used after a SHOW_RANDOM, HIDE_RANDOM or INSERT_RANDOM command, since these are the commands that generate the random value used by SHOW_SAMERAND.
A generated random value will trigger only a single SAMERAND command. For each show command that is not triggered, the chances of later SAMERAND commands triggering increases so that eventually one of the commands will trigger (assuming the total of the threshold values in the commands equal the range of the RANDOM command). If the total is less than the range of the RANDOM command, there will be a chance that none of the items will be shown.
For example, to show exactly one of four possible lines with equal probability:
<HIDE><SHOW_RANDOM 25> This is line 1. <HIDE><SHOW_SAMERAND 25> This is line 2. <HIDE><SHOW_SAMERAND 25> This is line 3. <HIDE><SHOW_SAMERAND 25> This is line 4. <SHOW>
In this case, a random value is generated, between 1 and 100. If the value is between 1 and 25, the first line will be displayed. If the random value is between 26 and 50, the second line will be displayed. The third and fourth lines will be handled similarly. If you want to display the random value as well, use:
The random # is: <INSERT_RANDOM> <P> <HIDE><SHOW_SAMERAND 25> This is line 1. <HIDE><SHOW_SAMERAND 25> This is line 2. <HIDE><SHOW_SAMERAND 25> This is line 3. <HIDE><SHOW_SAMERAND 25> This is line 4. <SHOW>
Here is another example. In this case, one graphic will be randomly displayed:
<HIDE><SHOW_RANDOM 2> <IMG SRC=/Images/VeryRare.GIF> <HIDE><SHOW_SAMERAND 5> <IMG SRC=/Images/Rare.GIF> <HIDE><SHOW_SAMERAND 15> <IMG SRC=/Images/Occasional.GIF> <HIDE><SHOW_SAMERAND 30> <IMG SRC=/Images/Common.GIF> <HIDE><SHOW_SAMERAND 48> <IMG SRC=/Images/Frequent.GIF> <SHOW>
If a range other than the default has been specified in the preceding RANDOM command, the text following will be shown a fraction of the times the page is served defined by the threshold in the SHOW_SAMERAND command and the range in the preceding RANDOM command. For example:
<HIDE><SHOW_RANDOM 1 3> This will only be shown 1/3 of the time. <HIDE><SHOW_SAMERAND 1> This will be shown 1/3 of the time when the first line is not. <HIDE><SHOW_SAMERAND 1> This will be shown the remaining 1/3 of the time.
Copyright © 1996-1999 Maxum Development Corporation http://www.maxum.com/ |
Previous |
Next Contents |